﻿using System.Collections.Generic;

namespace OConf.Model.Common
{
    public class ReturnDataHelper<T>
    {
        /// <summary>
        /// 操作成功
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public static ReturnData<T> Success(string msg = "", T data = default(T))
        {
            ReturnData<T> result = new ReturnData<T>()
            {
                Code = (int)VabStateCode.StatusCode.服务器成功返回请求数据,
                Msg = msg,
                Data = data
            };
            return result;
        }

        /// <summary>
        /// 发生异常
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public static ReturnData<T> Exception(string msg = "", T data = default(T))
        {
            ReturnData<T> result = new ReturnData<T>()
            {
                Code = (int)VabStateCode.StatusCode.服务器发生错误,
                Msg = msg,
                Data = data
            };
            return result;
        }

        /// <summary>
        /// 令牌过期
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public static ReturnData<T> NeedLogin(string msg = "", T data = default(T))
        {
            ReturnData<T> result = new ReturnData<T>()
            {
                Code = (int)VabStateCode.StatusCode.令牌过期,
                Msg = msg,
                Data = data
            };
            return result;
        }

        /// <summary>
        /// 数据已存在
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public static ReturnData<T> Exists(string msg = "", T data = default(T))
        {
            ReturnData<T> result = new ReturnData<T>()
            {
                Code = (int)VabStateCode.StatusCode.数据已存在,
                Msg = msg,
                Data = data
            };
            return result;
        }

        /// <summary>
        /// 数据不存在
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public static ReturnData<T> NoExists(string msg = "", T data = default(T))
        {
            ReturnData<T> result = new ReturnData<T>()
            {
                Code = (int)VabStateCode.StatusCode.数据不存在,
                Msg = msg,
                Data = data
            };
            return result;
        }

        /// <summary>
        /// 请求参数错误
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public static ReturnData<T> ParamerError(string msg = "", T data = default(T))
        {
            ReturnData<T> result = new ReturnData<T>()
            {
                Code = (int)VabStateCode.StatusCode.请求参数错误,
                Msg = msg,
                Data = data
            };
            return result;
        }

        /// <summary>
        /// 操作失败
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public static ReturnData<T> Fail(string msg = "", T data = default(T))
        {
            ReturnData<T> result = new ReturnData<T>()
            {
                Code = (int)VabStateCode.StatusCode.操作失败,
                Msg = msg,
                Data = data
            };
            return result;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="code">状态码</param>
        /// <param name="msg">提示语</param>
        /// <param name="data">返回数据</param>
        /// <returns></returns>
        public static ReturnData<T> DiyResult(int code, string msg = "", T data = default(T))
        {
            ReturnData<T> result = new ReturnData<T>()
            {
                Code = code,
                Msg = msg,
                Data = data
            };
            return result;
        }

        /// <summary>
        /// 自定义结果
        /// </summary>
        /// <param name="statusCode"></param>
        /// <param name="msg"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public static ReturnData<T> CustomResult(int statusCode, string msg = "", T data = default(T))
        {
            ReturnData<T> result = new ReturnData<T>()
            {
                Code = statusCode,
                Msg = msg,
                Data = data
            };
            return result;
        }
    }
    /// <summary>
    /// 后端返回给前端的数据
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class ReturnData<T>
    {
        public int Code { get; set; }
        public string Msg { get; set; }
        public T Data { get; set; }
    }

    /// <summary>
    /// 后端返回前端界面表格信息数据
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class ReturnTableData<T>
    {
        public List<T> List { get; set; } = new List<T>();
        public int Total { get; set; }
    }

    /// <summary>
    /// 用户登录响应结果
    /// </summary>
    public class UserLoginResponse
    {
        /// <summary>
        /// 令牌
        /// </summary>
        public string token { get; set; }
    }

    /// <summary>
    /// 返回用户信息
    /// </summary>
    public class UserInfoResponse
    {
        public string[] Permissions { get; set; } = { "read:system", "write:system", "delete:system" };
        public string[] Roles { get; set; } = { "Admin" };
        public string Username { get; set; }
        public string Avatar { get; set; } = "https://i.gtimg.cn/club/item/face/img/8/15918_100.gif";
    }
}
